package com.shenmazong.servereduresume.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shenmazong.servereduresume.dto.TbInformation;
import com.shenmazong.servereduresume.dto.TbPractice;
import com.shenmazong.servereduresume.dto.TbProject;
import com.shenmazong.servereduresume.dto.TbSchoolyard;
import com.shenmazong.servereduresume.mapper.TbSchoolyardMapper;
import com.shenmazong.servereduresume.service.TbSchoolyardService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class TbSchoolyardServiceImpl extends ServiceImpl<TbSchoolyardMapper, TbSchoolyard>
implements TbSchoolyardService {

    @Autowired
    private TbSchoolyardMapper tbSchoolyardMapper;

    @Override
    public ResultResponse findByInformationId(BatchChooseIdVo batchChooseIdVo) {
        Object o = batchChooseIdVo.getParamMap().get("informationId");
        if (o==null){
            return ResultResponse.FAILED("非法参数");
        }
        List<TbSchoolyard> list = null;
        try {
            Long informationId= (Long) o;
            list = tbSchoolyardMapper.selectList(new QueryWrapper<TbSchoolyard>().lambda().eq(TbSchoolyard::getInformationId, informationId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS(list);
    }

    @Override
    public ResultResponse saveOrUpdateSchoolyard(TbSchoolyard tbSchoolyard) {
        try {
            if (tbSchoolyard.getSchoolyardId()==null) {
                tbSchoolyardMapper.insert(tbSchoolyard);
            }else {
                tbSchoolyardMapper.updateById(tbSchoolyard);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse deleteSchoolyard(BatchChooseIdVo batchChooseIdVo) {
        if (batchChooseIdVo.getIds().size() <= 0){
            return ResultResponse.FAILED("至少选择一个删除");
        }
        try {
            for (Long id : batchChooseIdVo.getIds()) {
                UpdateWrapper<TbSchoolyard> updateWrapper = new UpdateWrapper<TbSchoolyard>().eq("schoolyard_id", id);
                updateWrapper.set("delete_flag",1);
                tbSchoolyardMapper.delete(updateWrapper);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED();
        }
        return ResultResponse.SUCCESS();
    }
}




